package com.moss.common.domain;

import com.moss.common.constant.HttpStatus;
import lombok.Data;

import java.util.Arrays;
import java.util.List;

@Data
public class AjaxResult<T> {


    /**
     * 状态码
     */
    public Integer code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 分页返回总数
     */
    private Long total;

    /**
     * 返回数据
     */
    private T data;

    public AjaxResult() {
    }

    public AjaxResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public AjaxResult(Integer code, String msg, T data,long total) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }

    public AjaxResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static AjaxResult<Void> success(){
        return new AjaxResult<>(HttpStatus.SUCCESS,"操作成功");
    }

    public static <T> AjaxResult<T> error(){
        return new AjaxResult<>(HttpStatus.ERROR,"服务发生未知异常");
    }

    public static <T> AjaxResult<T> error(T data){
        return new AjaxResult<>(500,"服务发生未知异常",data);
    }

    public static <T> AjaxResult<T> error(int code,String data){
        return new AjaxResult<>(code,data);
    }

    public static <T> AjaxResult<T> success(T data){
        return new AjaxResult<>(HttpStatus.SUCCESS,"操作成功",data);
    }

    public static <T> AjaxResult<T> success(T data,long total){
        return new AjaxResult<>(HttpStatus.SUCCESS,"操作成功",data,total);
    }
}
